<?php
/**
 * 成功案列
 * User: Administrator
 * Date: 2022/3/10
 * Time: 16:02
 */

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
use think\Request;
class SuccessCase extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function list()
    {
        if (!Request::instance()->isGet())
            $this->error('请求方式不正确');

        $page = input('get.page',1);
        $limit = input('get.limit',10);
        $where = [];
        if($category_about_id = input('get.category_about_id'))
        {
            $where['category_about_id'] = $category_about_id;
        }

        if($title = input('get.title'))
        {
            $where['title'] = ['like','%'.$title.'%'];
        }
        $list = Db::name('success_case')->field('id,title,image')->where($where)->paginate($limit,'',['page'=>$page]);
        if($list)
            $this->success('',$list);
        $this->error('暂无数据');
    }

    /**
     * 分类列表
     */
    public function typeList()
    {
        if (!Request::instance()->isGet())
            $this->error('请求方式不正确');

        $list = Db::name('category_about')->field('id,title')->select();
        if($list)
            $this->success('',$list);
        $this->error('暂无数据');
    }

    /**
     * 详情
     */
    public function detail()
    {
        if (!Request::instance()->isGet())
            $this->error('请求方式不正确');
        if(!$id = input('get.id'))
        {
            $this->error('缺少参数');
        }

        $info = Db::name('success_case')->field('id,title,look,content,createtime')->where('id',$id)->find();
        if(!$info)
            $this->error('暂无数据');
        Db::name('success_case')->where('id',$id)->setInc('look');
        $info['time'] = date('Y-m-d',$info['createtime']);
        $this->success('',$info);
    }
}